package com.example.yk2021xm04.controller;


import com.example.yk2021xm04.model.RespBean;
import com.example.yk2021xm04.pojo.Meeting;
import com.example.yk2021xm04.query.MeetingQuery;
import com.example.yk2021xm04.service.IMeetingService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZengQi
 * @since 2021-12-08
 */
@Controller
@RequestMapping("/meeting")
public class MeetingController {
    @Resource
    private IMeetingService meetingService;

    @RequestMapping("index")
    public String index() { return "meeting/meeting";}

    @RequestMapping("addOrUpdateMeetingPage")
    public String addOrUpdatePage(Integer id, Model model) {
        if (null!=id) {
            model.addAttribute("meeting",meetingService.getById(id));
        }
        return "meeting/add_update";
    }

    @RequestMapping("list")
    @ResponseBody
    public Map<String, Object> meetingList(MeetingQuery meetingQuery) {
        return meetingService.meetingList(meetingQuery);
    }

    @RequestMapping("delete")
    @ResponseBody
    public RespBean deleteMeeting(Integer[] ids) {
        meetingService.deleteMeeting(ids);
        return RespBean.success("通知记录删除成功");
    }

    @RequestMapping("add")
    @ResponseBody
    public RespBean addMeeting(Meeting meeting) {
        meetingService.addMeeting(meeting);
        return RespBean.success("通知记录添加成功");
    }


    @RequestMapping("update")
    @ResponseBody
    public RespBean updateMeeting(Meeting meeting) {
        meetingService.updateMeeting(meeting);
        return RespBean.success("通知记录更新成功");
    }

}
